package com.rbc.rlslips.entrypoint;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;

import org.apache.log4j.Logger;

import com.rbc.rlslips.ServiceManager.ServiceManager;
import com.rbc.rlslips.enums.PropertiesKeysEnum;
import com.rbc.rlslips.enums.ServicesEnum;
import com.rbc.rlslips.factory.ServiceManagerFactory;
import com.rbc.rlslips.logger.RLLogger;
import com.rbc.rlslips.properties.manager.PropertiesReader;

public class RLSlipsUtility {

	/**
	 * @param args
	 * 
	 */
	
	private static Logger logger = Logger.getLogger(RLSlipsUtility.class);
	
	static{
		RLLogger.info(logger,"RLSlipsUtility Initialization started.Setting the system variables");
		System.setProperty("javax.net.ssl.trustStore",PropertiesReader.getProperty(PropertiesKeysEnum.TRUST_STORE_PATH_KEY));
		System.setProperty("javax.net.ssl.trustStorePassword",PropertiesReader.getProperty(PropertiesKeysEnum.KEY_STORE_PSWD_KEY));
		System.setProperty("java.protocol.handler.pkgs",PropertiesReader.getProperty(PropertiesKeysEnum.PROTOCOL_PKGS_KEY));
		System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", PropertiesReader.getProperty(PropertiesKeysEnum.HTTP_PIPE_DUMP_KEY));
		System.setProperty("http.proxyHost", PropertiesReader.getProperty(PropertiesKeysEnum.HTTP_PROXY_HOST_KEY));  
		System.setProperty("http.proxyPort", PropertiesReader.getProperty(PropertiesKeysEnum.HTTP_PROXY_PORT_KEY));      
		System.setProperty("https.proxyHost", PropertiesReader.getProperty(PropertiesKeysEnum.HTTPS_PROXY_HOST_KEY));  
		System.setProperty("https.proxyPort", PropertiesReader.getProperty(PropertiesKeysEnum.HTTPS_PROXY_PORT_KEY));
		RLLogger.info(logger,"RLSlipsUtility Initialization Ended.");
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ServiceManagerFactory managerFactory = ServiceManagerFactory.newInstance();
		QName annuaireQName = new QName(
				PropertiesReader.getProperty(PropertiesKeysEnum.QNAME_ANNUAIRE_URI_KEY),
				PropertiesReader.getProperty(PropertiesKeysEnum.QNAME_ANNUAIRE_LOCAL_PART_KEY));
		URL annuaireURL = null;
		ServiceManager serviceManager = null;
		try {
			annuaireURL = new URL(
					PropertiesReader.getProperty(PropertiesKeysEnum.QNAME_ANNUAIRE_URL)
					);
			serviceManager = managerFactory.createServiceManagerInstance(ServicesEnum.ANNUAIRE_LOGICIEL_SERVICE, annuaireQName, annuaireURL);
			serviceManager.invokeService();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
